package com.xiemingtian.navdemo

import android.os.Bundle
import android.os.Handler
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.Navigation

class LaunchFragment : Fragment() {

    private var index = 1
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        index = arguments?.getInt("INDEX") ?: 1
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_blank, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        Handler().postDelayed({
            val controller = Navigation.findNavController(view)
            val activity = activity as MainActivity
            if (activity.isLogin()){
                val data = Bundle()
                data.putString("name",activity.getName())
                controller.navigate(R.id.action_launchFragment_to_homeFragment,data,Util.launchNavOpt)
            }
            else{
                controller.navigate(R.id.action_launchFragment_to_loginFragment,null,Util.launchNavOpt)
            }
        },1000)
    }
}
